import { createRouter, createWebHistory } from 'vue-router'
import Layout from '../views/Layout.vue'
import Dashboard from '../views/Dashboard.vue'
import ModelList from '../views/models/ModelList.vue'
import ModelForm from '../views/models/ModelForm.vue'
import DataList from '../views/data/DataList.vue'
import DataForm from '../views/data/DataForm.vue'
import Settings from '../views/Settings.vue'
import ApiDocs from '../views/ApiDocs.vue'
import IPAuthorization from '../views/IPAuthorization.vue'

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '',
        name: 'Dashboard',
        component: Dashboard,
        meta: { title: '仪表盘' }
      },
      {
        path: 'models',
        name: 'ModelList',
        component: ModelList,
        meta: { title: '模型列表' }
      },
      {
        path: 'models/create',
        name: 'CreateModel',
        component: ModelForm,
        meta: { title: '创建模型' }
      },
      {
        path: 'models/:id/edit',
        name: 'EditModel',
        component: ModelForm,
        meta: { title: '编辑模型' },
        props: true
      },
      {
        path: 'data/:model',
        name: 'DataList',
        component: DataList,
        meta: { 
          title: '数据列表',
          dynamicTitle: (route) => {
            // 动态标题将在组件内部处理
            return '数据列表'
          }
        },
        props: true
      },
      {
        path: 'data/:model/create',
        name: 'CreateData',
        component: DataForm,
        meta: { title: '创建数据' },
        props: true
      },
      {
        path: 'data/:model/:id/edit',
        name: 'EditData',
        component: DataForm,
        meta: { title: '编辑数据' },
        props: true
      },
      {
        path: 'settings',
        name: 'Settings',
        component: Settings,
        meta: { title: '系统设置' }
      },
      {
        path: 'api-docs',
        name: 'ApiDocs',
        component: ApiDocs,
        meta: { title: 'API接口文档' }
      },
      {
        path: '/ip-authorization',
        name: 'IPAuthorization',
        component: IPAuthorization,
        meta: {
          title: 'IP授权管理',
          icon: 'lock-outlined'
        }
      }
    ]
  },
  // 添加一个通配符路由，处理所有未匹配的路径
  {
    path: '/:pathMatch(.*)*',
    redirect: '/'
  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

export default router 